package com.example.alarm.mvvm.widget

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import android.widget.Toast
import com.blankj.utilcode.util.SizeUtils
import com.example.alarm.R
import com.gsafety.libraryktx.adapter.RvAttachPicAdapter
import com.gsafety.libraryktx.bean.AttachBean
import com.gsafety.libraryktx.config.Constant
import com.gsafety.libraryktx.util.AppUtil
import kotlinx.android.synthetic.main.alarm_feedback_layout.*

/**
 * @author : lianbing.geng
 * @date : 2020/7/4 10:41
 */
class DealStatusSelectDialog(context: Context?) : Dialog(context!!, R.style.alarm_MyDialog), View.OnClickListener {
    var receiveMsg = ""
    var dealType = Constant.DEAL_STATE_RECEIVE

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.alarm_feedback_layout)
        receiveMsg = context?.resources?.getString(R.string.alarm_going_to_there)!!
        val window = window
        val wmParams = window!!.attributes
        wmParams.gravity = Gravity.LEFT or Gravity.CENTER
        wmParams.x = 0
        wmParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

        // 设置悬浮窗口长宽数据
        wmParams.width = ViewGroup.LayoutParams.MATCH_PARENT
        wmParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
        initView()
    }
    private fun initView() {
        findViewById<TextView>(R.id.tv_cancel).setOnClickListener {
            dismiss()
        }
        findViewById<TextView>(R.id.tv_sure).setOnClickListener(this)
        rb_going_to.text = if(dealType == Constant.DEAL_STATE_RECEIVE) context.resources.getString(R.string.alarm_going_to_there) else context.resources.getString(R.string.alarm_sure_finish)
        rb_at_there.text = if(dealType == Constant.DEAL_STATE_RECEIVE) context.resources.getString(R.string.alarm_has_at_there) else context.resources.getString(R.string.alarm_sure_no_pass)
        rg_deal_type.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.rb_going_to->{
                    receiveMsg = rb_going_to.text.toString()
                }
                R.id.rb_at_there->{
                    receiveMsg = rb_at_there.text.toString()
                }
            }
        }
        if(dealType == Constant.DEAL_STATE_RESOLVE){
            rb_going_to.compoundDrawablePadding = SizeUtils.dp2px(125.0f)
            tv_receive_title.text = "预警解除"
        }else{
            tv_receive_title.text = "预警接警"
        }
    }

    override fun onClick(v: View?) {
        if(v?.id == R.id.tv_sure){
            mOnReceiveAlarmClickListener?.receiveAlarmClick(receiveMsg)
            dismiss()
        }
    }

    var mOnReceiveAlarmClickListener:OnReceiveAlarmClickListener? = null
    interface OnReceiveAlarmClickListener{
        fun receiveAlarmClick(msg:String)
    }
}